﻿namespace GoodAdmin.System;

/// <summary>
/// 系统菜单表
/// </summary>
[SugarTable(tableName: "Sys_Menu", "系统菜单表")]
public class SysMenu: BaseSystemEntityHasPid
{
    /// <summary>
    /// 标题 
    ///</summary>
    [SugarColumn(ColumnName = "Title", ColumnDescription = "标题", Length = 200)]
    public virtual string Title { get; set; }
    /// <summary>
    /// 别名 
    ///</summary>
    [SugarColumn(ColumnName = "Name", ColumnDescription = "别名", Length = 200, IsNullable = true)]
    public string Name { get; set; }
    /// <summary>
    /// 编码 
    ///</summary>
    [SugarColumn(ColumnName = "Code", ColumnDescription = "编码", Length = 200, IsNullable = true)]
    public virtual string Code { get; set; }
    /// <summary>
    /// 分类 
    ///</summary>
    [SugarColumn(ColumnName = "Category", ColumnDescription = "分类", Length = 200, IsNullable = true)]
    public string Category { get; set; }
    /// <summary>
    /// 菜单类型 
    ///</summary>
    [SugarColumn(ColumnName = "MenuType", ColumnDescription = "菜单类型", Length = 200, IsNullable = true)]
    public virtual string MenuType { get; set; }
    /// <summary>
    /// 路径 
    ///</summary>
    [SugarColumn(ColumnName = "Path", ColumnDescription = "路径", IsNullable = true)]
    public virtual string Path { get; set; }
    /// <summary>
    /// 组件 
    ///</summary>
    [SugarColumn(ColumnName = "Component", ColumnDescription = "组件", Length = 200, IsNullable = true)]
    public string Component { get; set; }
    /// <summary>
    /// 图标 
    ///</summary>
    [SugarColumn(ColumnName = "Icon", ColumnDescription = "图标", Length = 200, IsNullable = true)]
    public virtual string Icon { get; set; }
    /// <summary>
    /// 颜色 
    ///</summary>
    [SugarColumn(ColumnName = "Color", ColumnDescription = "颜色", Length = 200, IsNullable = true)]
    public string Color { get; set; }

    /// <summary>
    /// 是否缓存
    /// </summary>
    [SugarColumn(ColumnName = "IsKeepAlive", ColumnDescription = "是否缓存")]
    public bool IsKeepAlive { get; set; } = true;

    /// <summary>
    /// 是否隐藏
    /// </summary>
    [SugarColumn(ColumnName = "IsHide", ColumnDescription = "是否隐藏")]
    public bool IsHide { get; set; } = false;

    /// <summary>
    /// 是否外链
    /// </summary>
    [SugarColumn(ColumnName = "IsLink", ColumnDescription = "是否外链")]
    public bool IsLink { get; set; } = false;
    /// <summary>
    /// 链接地址
    /// </summary>
    [SugarColumn(ColumnName = "OutLink", ColumnDescription = "链接地址", Length = 1, IsNullable = true)]
    public string OutLink { get; set; }
    /// <summary>
    /// 排序码 
    ///</summary>
    [SugarColumn(ColumnName = "SortCode", ColumnDescription = "排序码", IsNullable = true)]
    public int SortCode { get; set; } = 999;

    [SugarColumn(IsIgnore = true)]
    public MenuMeta Meta { get; set; }
    /// <summary>
    /// 子菜单
    /// </summary>
    [SugarColumn(IsIgnore = true)]
    public List<SysMenu> Children { get; set; }
}

/// <summary>
/// 菜单Meta配置
/// </summary>
public class MenuMeta
{
    /// <summary>
    /// 标题
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 图标
    /// </summary>
    public string Icon { get; set; }

    /// <summary>
    /// 是否隐藏
    /// </summary>
    public bool IsHide { get; set; }

    /// <summary>
    /// 是否缓存
    /// </summary>
    public bool IsKeepAlive { get; set; }

    public bool IsLink { get; set; }
}

/// <summary>
/// 配置菜单对象映射
/// </summary>
public class SysMenuMapper : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        config.ForType<SysMenu, MenuMeta>()
            .Map(t => t.Title, o => o.Title)
            .Map(t => t.Icon, o => o.Icon)
            .Map(t => t.IsHide, o => o.IsHide)
            .Map(t => t.IsKeepAlive, o => o.IsKeepAlive);
    }
}



public class ApiResource
{
    /// <summary>
    /// 控制器路由
    /// </summary>
    public string ControllerRoute { get; set; }

    /// <summary>
    /// 接口描述
    /// </summary>
    public string ApiName { get; set; }


    /// <summary>
    /// 路由名称
    /// </summary>
    public string ApiRoute { get; set; }


    /// <summary>
    /// 资源名称
    /// </summary>
    public string ResourceName { get; set; }
}